package com.event.multicaster.impl;

import com.event.event.WeatherEvent;
import com.event.listener.WeatherListener;
import com.event.multicaster.EventMulticaster;

import java.util.ArrayList;
import java.util.List;

public class WeatherEventMulticaster implements EventMulticaster {

    private List<WeatherListener> listenerList = new ArrayList<>();

    public void multicastEvent(WeatherEvent event) {
        System.out.println("==========开始事件广播==========");
        listenerList.forEach(i -> i.onWeatherEvent(event));
        System.out.println("==========结束事件广播==========");
    }

    public void addListener(WeatherListener listener) {
        listenerList.add(listener);
    }

    public void removeListener(WeatherListener listener) {
        listenerList.remove(listener);
    }
}
